<template>
	<view class="custom-tab-bar">
		<view v-for="(item, index) in tabList" :key="index" class="tab-box" @click="switchTab(item, index)">
			<view v-if="item.text" class="tab-item">
				<image :src="current === index ? item.selectedIconPath : item.iconPath" class="tab-icon" />
				<text :class="{ selectedTab: current === index }" class="tab-text">{{ item.text }}</text>
			</view>
			<view v-else class="tab-middle">
				<uni-icons type="mic-filled" size="35" color="#ffffff"></uni-icons>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		emits: ['tab-change'],
		data() {
			return {
				tabList: [{
						pagePath: 'pages/tabBars/home/home',
						iconPath: `${this.$ImgBaseUrl}home.png`,
						selectedIconPath: `${this.$ImgBaseUrl}homeHL.png`,
						text: '首页',
					},
					{
						pagePath: 'pages/tabBars/viewSonic/viewSonic',
						iconPath: `${this.$ImgBaseUrl}viewSonic.png`,
						selectedIconPath: `${this.$ImgBaseUrl}viewSonicHL.png`,
						text: '优派',
					},
					{
						pagePath: 'pages/tabBars/nearby/nearby',
						iconPath: '',
						selectedIconPath: `${this.$ImgBaseUrl}nearbyHL.png`,
						text: '',
					},
					{
						pagePath: 'pages/tabBars/nearby/nearby',
						iconPath: `${this.$ImgBaseUrl}nearby.png`,
						selectedIconPath: `${this.$ImgBaseUrl}nearbyHL.png`,
						text: '附近',
					},
					{
						pagePath: 'pages/tabBars/my/my',
						iconPath: `${this.$ImgBaseUrl}my.png`,
						selectedIconPath: `${this.$ImgBaseUrl}myHL.png`,
						text: '我的',
					},
				],
				current: 0,
				color: '#666666',
				selectedColor: '#2F80ED',
			};
		},
		methods: {
			switchTab(item, index) {
				if (this.current === index) return;
				this.current = index;
				this.$emit('tab-change', index);
			},
		},
		mounted() {
			// console.log
		},
	};
</script>

<style lang="less" scoped>
	.custom-tab-bar {
		margin: 0 24rpx;
		position: fixed;
		bottom: 51rpx;
		left: 0;
		right: 0;
		display: flex;
		justify-content: space-around;
		align-items: center;
		height: 98rpx;
		background: #FFFFFF;
		box-shadow: 0px 2rpx 22rpx 0px #DDE1E7;
		border-radius: 49rpx;
		z-index: 9999;
	}

	.tab-middle {
		width: 98rpx;
		height: 98rpx;
		border-radius: 50%;
		background: linear-gradient(144deg, #63E2FF 0%, #B066FE 100%);
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		bottom: 24rpx;
		left: 50%;
		transform: translateX(-50%);
	}

	.tab-item {
		display: flex;
		flex-direction: column;
		align-items: center;

		.tab-icon {
			width: 34rpx;
			height: 34rpx;
		}

		.tab-text {
			font-weight: 400;
			font-size: 22rpx;
			color: #666666;
			margin-top: 10rpx;
		}

		.selectedTab {
			color: #2F80ED;
		}
	}
</style>